package com.limao.Tool;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.limao.CacheManager.BaseDataCacheManager;
import com.limao.CacheManager.CrowdOrderCache;
import com.limao.CacheManager.CrowdUserAuthCache;
import com.limao.CacheManager.SessionCacheManager;
import com.limao.CacheManager.Verson_CacheManager;
import com.limao.CacheManager.mobile_codeCacheManger;
import com.limao.CacheManager.table_ideCacheManager;
import com.limao.CacheManager.user_addressCacheManager;
import com.limao.CacheManager.user_offline_CacheManager;
import com.limao.DBDataClass.CrowdUserAuthClass;
import com.limao.DbConnection.DbConnectionManager;
import com.limao.Model.LzPluginException;
import com.limao.Model.RecvData;

public class CacheClass {
	
	public static int isOut=0;  //0外网   1测试外网  2内网 
	
	public static int ISDEBUG= 0; 	//是否调试模式 0:否 1是
	
	public static int iscrypt=0; //0不加密   1加密  
	
	public static int task=0; //是否开启定时任务 0否   1是
	
	public static boolean istrade=false; //0不模拟交易   1模拟交易 
	public static float priceToHigh=80; // ?% 价格向上走
	
	public static long Maintenance_Start_time=0;
	
	public static String imgUrl2="http://192.168.0.177:8080/crowd";
	public static String imgUrl1="http://image.91limao.com/";
	public static String imgUrl0="http://image.91limao.com/";	
	
	public static String webUrl2="http://192.168.0.177:8080/crowd";
	public static String webUrl1="https://www.91limao.com/";
	public static String webUrl0="http://newapi.91limao.com/";
	
	public static String mw2="";
	public static String mw1="";
	public static String mw0="";
	
	public static String tradeulr2="";
	public static String tradeulr1="";
	public static String tradeulr0="";
	
	
	
	
	public static String ShareUrl="http://newapi.91limao.com/";  //分享链接
	
	
    public static final int SYSTEM = 17;
    public static final int ROSTER = 18;
    public static final int OFFLINE = 19;
    public static final int MUC_ROOM = 23;
    public static final int SECURITY_AUDIT = 25;
    public static final int MUC_SERVICE = 26;

    public static final long SECOND = 1000;
    public static final long MINUTE = 60 * SECOND;
    public static final long HOUR = 60 * MINUTE;
    public static final long DAY = 24 * HOUR;
    public static final long WEEK = 7 * DAY;
	
    //打印出调试信息
    public static void Println(String info)
    {
    	if(ISDEBUG==1)
    		System.out.println(info);
    }
    
    public static String isLogin(HttpServletRequest request,HttpServletResponse response)
    {
    	HttpSession session=request.getSession();
    	String Session_Userid=(String)session.getAttribute("userid");
 
    	String selfSessionId=getCookieSession(request);
		String cookie_Userid=SessionCacheManager.getInstance().GetSessionCache(selfSessionId);
		
		if(!CacheClass.isEmpty(Session_Userid) && !CacheClass.isEmpty(cookie_Userid) && CacheClass.myEqualsIgnoreCase(Session_Userid, cookie_Userid))
		{
			return Session_Userid;
		}
		else if(!CacheClass.isEmpty(Session_Userid) && CacheClass.isEmpty(cookie_Userid))
		{
			selfSessionId=session.getId();
			SessionCacheManager.getInstance().PutSessionCache(selfSessionId, Session_Userid);
			setCookieSession(response,selfSessionId);
			session.setAttribute("selfSessionId", selfSessionId);
			return Session_Userid;
		}
		else if(CacheClass.isEmpty(Session_Userid) && !CacheClass.isEmpty(cookie_Userid))
		{
			session.setAttribute("userid",cookie_Userid);
			
			selfSessionId=session.getId();
			SessionCacheManager.getInstance().PutSessionCache(selfSessionId, Session_Userid);
			setCookieSession(response,selfSessionId);
			session.setAttribute("selfSessionId", selfSessionId);
			
			return cookie_Userid;
		}
	
		return null;

    }
    
    public static String isLogin_token(HttpServletRequest request,HttpServletResponse response)
    {
    	String token=request.getHeader("token");
    	if(CacheClass.isEmpty(token)) return null;
    	HttpSession session=request.getSession();
    	String cookie_Userid=SessionCacheManager.getInstance().GetSessionCache(token);
    	String Session_Userid=(String)session.getAttribute("userid");
 
    	
    	String selfSessionId=null;
		
		
		if(!CacheClass.isEmpty(Session_Userid) && !CacheClass.isEmpty(cookie_Userid) && CacheClass.myEqualsIgnoreCase(Session_Userid, cookie_Userid))
		{
			return Session_Userid;
		}
		else if(!CacheClass.isEmpty(Session_Userid) && CacheClass.isEmpty(cookie_Userid))
		{
			CrowdUserAuthClass tmp= CrowdUserAuthCache.getInstance().getUser(CacheClass.getIntValue(Session_Userid));
			selfSessionId=session.getId();
			SessionCacheManager.getInstance().PutSessionCache(selfSessionId, Session_Userid);
			setCookieSession(response,selfSessionId);
			session.setAttribute("selfSessionId", selfSessionId);
			CacheClass.Login(session,selfSessionId,tmp);
			return Session_Userid;
		}
		else if(CacheClass.isEmpty(Session_Userid) && !CacheClass.isEmpty(cookie_Userid))
		{
			CrowdUserAuthClass tmp= CrowdUserAuthCache.getInstance().getUser(CacheClass.getIntValue(cookie_Userid));
			session.setAttribute("userid",cookie_Userid);
			
			selfSessionId=session.getId();
			SessionCacheManager.getInstance().PutSessionCache(selfSessionId, Session_Userid);
			setCookieSession(response,selfSessionId);
			session.setAttribute("selfSessionId", selfSessionId);
			CacheClass.Login(session,selfSessionId,tmp);
			return cookie_Userid;
		}
		
		return null;

    }
    
    
    public static String MobileStar(String mobile)
    {
    	return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
    }
    
    public static void outLogin(HttpSession session,String selfSessionId)
    {
		session.setAttribute("userid", null);
		session.setAttribute("userclass", null);
		session.setAttribute("userobj", null);
		session.setAttribute("selfSessionId", "");
		session.invalidate();
		SessionCacheManager.getInstance().ClearObjectCache(selfSessionId);
    }
    
    public static void Login(HttpSession session,String selfSessionId,CrowdUserAuthClass tmp)
    {
    	
		SessionCacheManager.getInstance().PutSessionCache(selfSessionId, tmp.userid);
		session.setAttribute("userid", tmp.userid);
		session.setAttribute("userclass", tmp);
		session.setAttribute("userobj", JSON.toJSONString(tmp));
		session.setAttribute("selfSessionId", selfSessionId);
		System.out.print("login 登陆成功 sessionId="+selfSessionId+" userid="+tmp.userid);
    }
  
    public static String getCookieSession(HttpServletRequest request)
	{
		
		Cookie[]   cookies = request.getCookies();
        //cookies不为空     
        if(cookies!=null)      
        {    
    	  for(Cookie cookieTemp : cookies){
              String   cookieIdentity = cookieTemp.getName();      
              //查找身份串      
              if(cookieIdentity.equals("selfSession"))      
              {   
            	  return  cookieTemp.getValue();
              }  
    	   }
        } 
        return null;
	}
	
    public static HttpServletResponse setCookieSession(HttpServletResponse response,String SessionId)
	{
		Cookie selfSession = new Cookie("selfSession",SessionId);
		
		selfSession.setDomain(getHost());
		selfSession.setPath("/");
		response.addCookie(selfSession);
       
		return response;
	}

    
	public static int getCharacterPosition(String src, String find, int num) {
		// 这里是获取"find"符号的位置
		Matcher slashMatcher = Pattern.compile("find").matcher(src);
		int mIdx = 0;
		while (slashMatcher.find()) {
			mIdx++;
			// 当"#"符号第num次出现的位置
			if (mIdx == num) {
				break;
			}
		}
		if (mIdx == num)
			return slashMatcher.start();
		else
			return -1;

	}

	// 解析封装json格式客户端参数
	public static List<RecvData> getObjectList(String jsonString,
			Class<RecvData> cls) {
		if (isEmpty(jsonString))
			return null;
		List<RecvData> list = new ArrayList<RecvData>();
		try {
			list = JSON.parseArray(jsonString, cls);
		} catch (Exception e) {
		}
		return list;
	}
	
	public static String getMyUrl(String sessionId) {
		
		String introduceId=SessionCacheManager.getInstance().GetSessionCache(sessionId);
		
		if(CacheClass.isEmpty(introduceId))
			introduceId="";
		return getDomain()+"Reg?m=1&introduceId="+introduceId;
	}

	private static double EARTH_RADIUS = 3956 * 2;

	private static double rad(double d) {
		return d * Math.PI / 180.0;
	}

	public static String GetDistance(double lat1, double lng1, double lat2,
			double lng2) {

		double s = calculateDistance(lat1, lng1, lat2,lng2);

		if (s > 1) {
			DecimalFormat df = new DecimalFormat("###.0");// 保留一位小数
			return df.format(s) + "千米";
		} else {
			DecimalFormat df = new DecimalFormat("###");// 保留0位小数
			return df.format(s * 1000) + "米";

		}

	}
	
	public static double calculateDistance(double startlat, double startlon, double endlat,double endlon){
		double radLat1 = rad(startlat);
		double radLat2 = rad(endlat);
		double a = radLat1 - radLat2;
		double b = rad(startlon) - rad(endlon);
		double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
				+ Math.cos(radLat1) * Math.cos(radLat2)
				* Math.pow(Math.sin(b / 2), 2)));
		s = s * EARTH_RADIUS;
		
		return s;
	}

	public static String formatGPSDistance(String s) {
		if (s == null) {
			return "";
		}
		float distance = getFloatValue(s);
		if (distance > 1) {
			DecimalFormat df = new DecimalFormat("###.0");// 保留一位小数
			return df.format(distance) + "千米";
		} else {
			DecimalFormat df = new DecimalFormat("###");// 保留0位小数
			return df.format(distance * 1000) + "米";

		}

	}
	public static String getImgUrl()
	{
		if(isOut==2)
			return imgUrl2;
		else if(isOut==1)
			return imgUrl1;
		else 
			return imgUrl0;
	}
	
	public static String getDomain()
	{
		if(isOut==2)
			return webUrl2;
		else if(isOut==1)
			return webUrl1;
		else 
			return webUrl0;
	}
	
	
	public static String getMwUrl()
	{
		if(isOut==2)
			return mw2;
		else if(isOut==1)
			return mw1;
		else 
			return mw0;
	}
	
	public static String getTradeUlr()
	{
		if(isOut==2)
			return tradeulr2;
		else if(isOut==1)
			return tradeulr1;
		else 
			return tradeulr0;
	}
	
	public static String getShareUrl()
	{
		return ShareUrl;
	}
	
	public static String getNowShareUrl(HttpServletRequest request)
	{
		String path = request.getContextPath();
		return  request.getScheme() + "://"+ request.getServerName() +"/";
	}
	

	
	public static String getHost()
	{
		String webUrl=getDomain();

		if(webUrl.startsWith("http://") || webUrl.startsWith("https://"))
		{
			webUrl=webUrl.substring(webUrl.indexOf("//")+2);
		}
		if(webUrl.endsWith("/"))
			webUrl=webUrl.substring(0,webUrl.length()-1);
		if(webUrl.indexOf(":")>-1){
			webUrl=webUrl.split(":")[0];
		}
		
		if(isOut==0)
		{
			//webUrl=".net";//多域名
			webUrl=".91limao.com";//多域名
		}
		return webUrl;
	}

	public static String getClassPath()
	{
		 String path = DbConnectionManager.class.getResource("/").getPath().toString();
	     if(isOut==2){
	    	 return path ;
	     }
	     else
	     {
	    	 return "/"+path ;
	     }
	}
	// 是否派送范围坐标
	public static boolean isArriveGPS(double lat, double lon) {
		// 七星区
		// 110.3080993 110.349783
		// 25.303348 25.254862

		if (CacheClass.isRangeDouble(lat, 25.303348, 25.254862)
				&& CacheClass.isRangeDouble(lon, 110.3080993, 110.349783)) {
			return true;
		}
		return false;
	}

	// 产生一个随机数
	public static int getRandomNum(int minPort, int maxPort) {
		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			System.out.println("随机数计算,sleep出错");
		}
		int freePort = (int) (minPort + Math.round(Math.random()* (maxPort - minPort)));
		return freePort;
	}
	
	public static float getRandomNum(float minPort, float maxPort) {
		try {
			Thread.sleep(5);
		} catch (InterruptedException e) {
			System.out.println("随机数计算,sleep出错");
		}
		return (minPort + (float)(Math.random())* (maxPort - minPort));

	}

	/**基于 basePort 在百分之ratePort 内浮动   百分之pricePort价向上走**/
	public static float getRandomNum_base_rate(float basePort,float ratePort,float pricePort) {
		
		float ran=getRandomNum(0,100);
		if(ran<pricePort) //价格向上走
		{
			return getRandomNum(basePort,basePort+basePort*ratePort/100.0f);
		}
		else //价格向下走
		{
			return getRandomNum(basePort-basePort*ratePort/100.0f,basePort);
		}


	}
	
	public static long getRandomNum(long minPort, long maxPort) {
		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			System.out.println("随机数计算,sleep出错");
		}
		long freePort = (long) (minPort + Math.round(Math.random()
				* (maxPort - minPort)));
		return freePort;
	}
	
	//100000--999999之间的6位随机数
	public static String get6RandomCode(){
		return Math.round(Math.random() * 899999 + 100000)+"";
	}
	
	//10--99之间的2位随机数
	public static String get2RandomCode(){
		return Math.round(Math.random() * 89 + 10)+"";
	}
	
	public static float getRandomCode(int min,int max){
		try {
			Thread.sleep(5);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return  Math.round(Math.random() * (max-min) + min);
	}

	public static String GetPercent(String s1, String s2) {
		
		float r=100*CacheClass.getFloatValue(s1)/CacheClass.getFloatValue(s2);
		DecimalFormat df = new DecimalFormat("###.00");// 保留两位小数
		return df.format(r) + "%";

	}
	
	//保留两位小数
	public static String GetFloat_2(float r)
	{
		DecimalFormat df = new DecimalFormat("###.00");
		return df.format(r);
	}
	
	public static String GetDouble_2(double r)
	{
		DecimalFormat df = new DecimalFormat("###.00");
		return df.format(r);
	}
	
	public static boolean isEmpty(String s) {
		if (s == null || s.trim().length() == 0 || "null".equals(s))
			return true;
		else
			return false;
	}
	
	public static boolean isBank(String s) {
		if (s.contains("银行") && ( s.contains("支行") || s.contains("营业部") || s.contains("分理处")))
			return true;
		else
			return false;
	}

	public static String getStringValue(Object o) {
		if (o == null)
			return null;
		else
			return o.toString();
	}

	public static int getIntValue(String s) {
		if (isEmpty(s))
			return 0;
		else
			return Integer.parseInt(s.trim());
	}

	public static long getLongValue(String s) {
		if (isEmpty(s))
			return 0;
		else
			return Long.parseLong(s.trim());
	}

	public static float getFloatValue(String s) {
		if (isEmpty(s))
			return 0;
		else
			return Float.parseFloat(s.trim());
	}
	/**得到人民币 分, s 以元为单位的字符串 **/
	public static int getRMBIntValue(String s) {
		if (isEmpty(s))
			return 0;
		else
			return (int) (100*Float.parseFloat(s.trim()));
	}
	
	public static BigDecimal getBigDecimal(String s){
		if (isEmpty(s))
			return BigDecimal.valueOf(0);
		else
		{
			s=s.trim();
			BigDecimal d=new BigDecimal(s.trim());
			return new BigDecimal(s.trim());
		}
	}

	public static double getDoubleValue(String s) {
		if (isEmpty(s))
			return 0;
		else
			return Double.parseDouble(s.trim());
	}

	public static boolean myEqualsIgnoreCase(String s1, String s2) {
		if (isEmpty(s1) ) {
			if (isEmpty(s2))
				return true;
			else
				return false;

		} else {
			if(isEmpty(s2))
				return false;
			else
			return s1.equalsIgnoreCase(s2);
		}
	}

	public static boolean isMobileNO(String mobile) {
		String regExp = "^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\\d{8}$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(mobile);
		return m.find();
	}

	public static boolean isEMailNO(String mobile) {
		String regExp = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(mobile);
		return m.find();
	}

	   /*
    	校验过程： 
    1、从卡号最后一位数字开始，逆向将奇数位(1、3、5等等)相加。 
    2、从卡号最后一位数字开始，逆向将偶数位数字，先乘以2（如果乘积为两位数，将个位十位数字相加，即将其减去9），再求和。 
    3、将奇数位总和加上偶数位总和，结果应该可以被10整除。       
    */   
        /** 
        * 校验银行卡卡号 
        */  
       public static boolean checkBankCard(String bankCard) {  
                if(bankCard.length() < 15 || bankCard.length() > 19) {
                    return false;
                }
                char bit = getBankCardCheckCode(bankCard.substring(0, bankCard.length() - 1));  
                if(bit == 'N'){  
                    return false;  
                }  
                return bankCard.charAt(bankCard.length() - 1) == bit;  
       }  

       /** 
        * 从不含校验位的银行卡卡号采用 Luhm 校验算法获得校验位 
        * @param nonCheckCodeBankCard 
        * @return 
        */  
       public static char getBankCardCheckCode(String nonCheckCodeBankCard){  
           if(nonCheckCodeBankCard == null || nonCheckCodeBankCard.trim().length() == 0  
                   || !nonCheckCodeBankCard.matches("\\d+")) {  
               //如果传的不是数据返回N  
               return 'N';  
           }  
           char[] chs = nonCheckCodeBankCard.trim().toCharArray();  
           int luhmSum = 0;  
           for(int i = chs.length - 1, j = 0; i >= 0; i--, j++) {  
               int k = chs[i] - '0';  
               if(j % 2 == 0) {  
                   k *= 2;  
                   k = k / 10 + k % 10;  
               }  
               luhmSum += k;             
           }  
           return (luhmSum % 10 == 0) ? '0' : (char)((10 - luhmSum % 10) + '0');  
       }
	// 是否只含数字
	public static boolean isNO(String mobile) {
		if (isEmpty(mobile))
			return true;
		String regExp = "^[0-9]*$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(mobile);
		return m.find();
	}

	public static boolean isFloatNO(String mobile) {
		if (isEmpty(mobile))
			return true;
		String regExp = "\\d+\\.?\\d*";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(mobile);
		return m.find();
	}

	/**
	 * 判断number参数是否是整型数表示方式
	 * 
	 * @param number
	 * @return
	 */
	public static boolean isIntegerNumber1(String number) {
		if (isEmpty(number))
			return true;
		number = number.trim();
		String intNumRegex = "\\-{0,1}\\d+";// 整数的正则表达式
		if (number.matches(intNumRegex))
			return true;
		else
			return false;
	}

	/**
	 * 判断number参数是否是正整型数表示方式
	 * 
	 * @param number
	 * @return
	 */
	public static boolean isIntegerNumber2(String number) {
		if (isEmpty(number))
			return true;
		number = number.trim();
		String intNumRegex = "\\d+";// 整数的正则表达式
		if (number.matches(intNumRegex))
			return true;
		else
			return false;
	}
	
	/**
     * 判断身份证格式
     * 
     * @param idNum
     * @return
     */
    public static boolean isIdNum(String idNum) {

        // 中国公民身份证格式：长度为15或18位，最后一位可以为字母
        Pattern idNumPattern = Pattern.compile("(\\d{14}[0-9a-zA-Z])|(\\d{17}[0-9a-zA-Z])");

        // 格式验证
        if (!idNumPattern.matcher(idNum).matches())
            return false;

        // 合法性验证

        int year = 0;
        int month = 0;
        int day = 0;

        if (idNum.length() == 15) {

            // 一代身份证

            System.out.println("一代身份证：" + idNum);

            // 提取身份证上的前6位以及出生年月日
            Pattern birthDatePattern = Pattern.compile("\\d{6}(\\d{2})(\\d{2})(\\d{2}).*");

            Matcher birthDateMather = birthDatePattern.matcher(idNum);

            if (birthDateMather.find()) {

                year = Integer.valueOf("19" + birthDateMather.group(1));
                month = Integer.valueOf(birthDateMather.group(2));
                day = Integer.valueOf(birthDateMather.group(3));

            }

        } else if (idNum.length() == 18) {

            // 二代身份证

            System.out.println("二代身份证：" + idNum);

            // 提取身份证上的前6位以及出生年月日
            Pattern birthDatePattern = Pattern.compile("\\d{6}(\\d{4})(\\d{2})(\\d{2}).*");

            Matcher birthDateMather = birthDatePattern.matcher(idNum);

            if (birthDateMather.find()) {

                year = Integer.valueOf(birthDateMather.group(1));
                month = Integer.valueOf(birthDateMather.group(2));
                day = Integer.valueOf(birthDateMather.group(3));
            }

        }

        // 年份判断，100年前至今

        Calendar cal = Calendar.getInstance();

        // 当前年份
        int currentYear = cal.get(Calendar.YEAR);

        if (year <= currentYear - 100 || year > currentYear)
            return false;

        // 月份判断
        if (month < 1 || month > 12)
            return false;

        // 日期判断

        // 计算月份天数

        int dayCount = 31;

        switch (month) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            dayCount = 31;
            break;
        case 2:
            // 2月份判断是否为闰年
            if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
                dayCount = 29;
                break;
            } else {
                dayCount = 28;
                break;
            }
        case 4:
        case 6:
        case 9:
        case 11:
            dayCount = 30;
            break;
        }

        System.out.println(String.format("生日：%d年%d月%d日", year, month, day));

        System.out.println(month + "月份有：" + dayCount + "天");

        if (day < 1 || day > dayCount)
            return false;

        return true;
    }

	/**
	 * 获取当前毫秒-不含日期
	 * 
	 * @param number
	 * @return
	 */
	public static int getcurTime() {
		int time = (int) ((new Date().getTime() + 8 * 60 * 60 * 1000) % (24 * 3600 * 1000)); // 换算成毫秒数，对一天的毫秒数取余，就是当天的毫秒数
		return time;
	}
	
	//毫秒数转时/分格式
	public static String mscToTimeStr(int msc){
		int hour = (msc % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);  
	    int minute = (msc % (1000 * 60 * 60)) / (1000 * 60);
	    StringBuffer timeStr = new StringBuffer();
	    if(hour < 10){
	    	timeStr.append("0").append(hour);
	    }else{
	    	timeStr.append(hour);
	    }
	    timeStr.append(":");
	    if(minute < 10){
	    	timeStr.append("0").append(minute);
	    }else{
	    	timeStr.append(minute);
	    }
	    
	    return timeStr.toString();
	}

	public static long getTime() {
		return new Date().getTime();
	}
	
    public static int getDate() {
        return getIntValue(getDateFormat("yyyyMMdd").format(new Date()));
    }
	
	   /* 格式化去掉0的尾数 */
    public static String formatNoZero(double amount) {
        DecimalFormat df = new DecimalFormat("#0.00");
        String str = df.format(amount);
        if (str.endsWith("00")) {
            return str.substring(0, str.length() - 3);
        } else if (str.endsWith("0")) {
            return str.substring(0, str.length() - 1);
        } else {
            return str;
        }
    }
    
 
	
	
  
	/**
	 * 判断number参数是否是浮点数表示方式
	 * 
	 * @param number
	 * @return
	 */
	public static boolean isFloatPointNumber1(String number) {
		if (isEmpty(number))
			return true;
		number = number.trim();
		String pointPrefix = "(\\-|\\+){0,1}\\d*\\.\\d+";// 浮点数的正则表达式-小数点在中间与前面
		String pointSuffix = "(\\-|\\+){0,1}\\d+\\.";// 浮点数的正则表达式-小数点在后面
		String pointSuffix2 = "(\\-|\\+){0,1}\\d+";// 浮点数的正则表达式-无小数点
		if (number.matches(pointPrefix) || number.matches(pointSuffix)
				|| number.matches(pointSuffix2))
			return true;
		else
			return false;
	}

	/**
	 * 判断number参数是否是正浮点数表示方式
	 * 
	 * @param number
	 * @return
	 */
	public static boolean isFloatPointNumber2(String number) {
		if (isEmpty(number))
			return true;
		number = number.trim();
		String pointPrefix = "\\d*\\.\\d+";// 浮点数的正则表达式-小数点在中间与前面
		String pointSuffix = "\\d+\\.";// 浮点数的正则表达式-小数点在后面
		String pointSuffix2 = "\\d+";// 浮点数的正则表达式-无小数点
		if (number.matches(pointPrefix) || number.matches(pointSuffix)
				|| number.matches(pointSuffix2))
			return true;
		else
			return false;
	}

	/**
	 * 判断number参数是否在规定值范围内
	 * 
	 * @param number
	 * @return
	 */
	public static boolean isRangeDouble(Double number, Double min, Double max) {
		if (number >= min && number <= max)
			return true;
		else
			return false;
	}

	public static boolean isRangeInt(long number, long min, long max) {
		if (number >= min && number <= max)
			return true;
		else
			return false;
	}

	public static boolean isRangeStringLength(String s, int min, int max) {
		if (s.length() >= min && s.length() <= max)
			return true;
		else
			return false;
	}

	// YYYY-MM-DD 日期格式验证
	public static boolean isValidDate(String sDate) {
		String datePattern1 = "\\d{4}-\\d{2}-\\d{2}";
		String datePattern2 = "^((\\d{2}(([02468][048])|([13579][26]))"
				+ "[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|"
				+ "(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?"
				+ "((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?("
				+ "(((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?"
				+ "((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";
		if ((sDate != null)) {
			Pattern pattern = Pattern.compile(datePattern1);
			Matcher match = pattern.matcher(sDate);
			if (match.matches()) {
				pattern = Pattern.compile(datePattern2);
				match = pattern.matcher(sDate);
				return match.matches();
			} else {
				return false;
			}
		}
		return false;
	}

	// 根据生日计算年龄
	public static String getAge(String birthday_) {
		if (isEmpty(birthday_))
			return null;
		SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
		Date birthDay = null;
		try {
			birthDay = myFormatter.parse(birthday_);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}

		Calendar cal = Calendar.getInstance();

		if (cal.before(birthDay)) {
			throw new IllegalArgumentException(
					"The birthDay is before Now.It's unbelievable!");
		}

		int yearNow = cal.get(Calendar.YEAR);
		int monthNow = cal.get(Calendar.MONTH) + 1;
		int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);

		cal.setTime(birthDay);
		int yearBirth = cal.get(Calendar.YEAR);
		int monthBirth = cal.get(Calendar.MONTH);
		int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);

		int age = yearNow - yearBirth;

		if (monthNow <= monthBirth) {
			if (monthNow == monthBirth) {
				// monthNow==monthBirth
				if (dayOfMonthNow < dayOfMonthBirth) {
					age--;
				}
			} else {
				// monthNow>monthBirth
				age--;
			}
		}

		return age + "";
	}

	// ****************************************lz
	// 基础资料
	public static BaseDataCacheManager getSYS_BaseDataCacheManager() {
		return BaseDataCacheManager.getInstance();
	}

	public static mobile_codeCacheManger getMobileCodeCacheManger() {
		return mobile_codeCacheManger.getInstance();
	}

	// wawa_table_ide 各物品表的表标识与ID计数
	public static table_ideCacheManager getSYStable_ideCacheManager() {
		return table_ideCacheManager.getInstance();
	}


	public static Verson_CacheManager getSYS_VersonCacheManager() {
		return Verson_CacheManager.getInstance();
	}



	public static CrowdOrderCache getSYS_OrderCacheManager() {
		return CrowdOrderCache.getInstance();
	}


	
	// *******************************************************************************




	// user_setCacheManager 人物上下线
	public static user_offline_CacheManager getUSERuser_OfflineCacheManager() {
		return user_offline_CacheManager.getInstance();
	}

	// user_setCacheManager 人物地址
	public static user_addressCacheManager getUSER_addressCacheManager() {
		return user_addressCacheManager.getInstance();
	}


	// 店铺 地址_联系人_电话
	// 订单 地址_电话_联系人
	public static String[] pressAddress(String address)
			throws LzPluginException {
		String[] result = address.split("_");
		if (result.length != 3) {
			throw new LzPluginException(address + ":地址_联系人_电话--解析错误");
		}

		return result;
	}
	

	public final static int 	INTEGRAL_RATE=100;			//金额换算积分比率
	public final static float 	MONEY_RATE=0.01f;			//积分换算金额比率

	public static int MoneyToScore(String money) {
		return (int)( CacheClass.getFloatValue(money) * INTEGRAL_RATE );
	}

	public static int MoneyToScore(float money) {
		return (int)(money * INTEGRAL_RATE);
	}

	public static float ScoreToMoney(int score) {
		return (score) * MONEY_RATE;
	}
	
	public static BigDecimal getDiscount(String activite){
		BigDecimal discount = BigDecimal.valueOf(1);
		String[] sps = activite.split(";");
		for(String sp : sps){
			if(sp.indexOf("折扣") > 1){
				discount = BigDecimal.valueOf(getDoubleValue(sp.split("/")[1])/100);
			}
		}
		return discount;
	}
	

	
	public static int getmyid(String id_str)
	{
		if(id_str.contains("_"))
		{
			id_str=id_str.substring(0, id_str.indexOf("_"));
		}
		
		return getIntValue(id_str);
	}
	
	public static String getmyidStr(String id_str)
	{
		if(id_str.contains("_"))
		{
			id_str=id_str.substring(0, id_str.indexOf("_"));
		}
		
		return id_str;
	}
	
	/**众筹状态**/
	public static String getProjectState(String projectState) 
	{
		int state=CacheClass.getIntValue(projectState);
		switch(state)
		{
		case 0:
			return "下架";
		case 1:
			return "预热";
		case 2:
			return "推荐";
		case 3:
			return "热销";
		default:
			return "新品";
		}
	
	}
	
	/**众筹套餐含 的数量**/
	public static String getProjectNum(String num) 
	{
		if(isEmpty(num))
		{
			return num;
		}
		if(num.indexOf(".")>-1)
		{
			num=TrimEnd(TrimEnd(num,"0"),".");
			if(num.indexOf(".")>-1)
			{
				DecimalFormat df = new DecimalFormat("###.00");// 保留一位小数
				return df.format(CacheClass.getFloatValue(num));
			}
			return num;
		}
		else 
			return num;
	}	
	
	public static String TrimEnd(String Str,String trimStr)
	{ 
			if(isEmpty(trimStr)){return Str;} 
			while(true)
			{ 
				if(!Str.endsWith(trimStr))
				{ 
					break; 
				} 
				Str = Str.substring(0,Str.length()-trimStr.length()); 
			} 
			return Str; 
	}
	
	/**众筹进度**/
	public static String getProjectProess(String nowrmb,String targetrmb) 
	{
		float rate=0;
		if(!CacheClass.isEmpty(targetrmb))
		{
			rate= 100*CacheClass.getFloatValue(nowrmb)/CacheClass.getFloatValue(targetrmb);
		}
		DecimalFormat df = new DecimalFormat("###.00");// 保留一位小数
		return df.format(rate);

	}
	/**众筹剩余天数 输入:20161020163000  d2-now 输出天数**/
	public static String getProjectDays(String d2) 
	{   
		//20161020163000

		d2=d2.substring(0, d2.length()-6);
		
		SimpleDateFormat smdf = new SimpleDateFormat( "yyyyMMdd");
		String d1=smdf.format(new Date());
		
		Calendar c1 = Calendar.getInstance();
		Calendar c2 = Calendar.getInstance();
		try {
			
			
			c1.setTime(new SimpleDateFormat("yyyyMMdd").parse(d1));
			c2.setTime(new SimpleDateFormat("yyyyMMdd").parse(d2));
			return (int) ((c2.getTimeInMillis() - c1.getTimeInMillis()) / (3600 * 24 * 1000))+"";
		} catch (ParseException e1) {
			e1.printStackTrace();
		}  
 
		return "";
	}
	
	/**众筹剩余天数 输入:20161020  d2-now 输出天数**/
	public static String getProjectDays2(String d2) 
	{   
	
		SimpleDateFormat smdf = new SimpleDateFormat( "yyyyMMdd");
		String d1=smdf.format(new Date());
		
		Calendar c1 = Calendar.getInstance();
		Calendar c2 = Calendar.getInstance();
		try {
			
			
			c1.setTime(new SimpleDateFormat("yyyyMMdd").parse(d1));
			c2.setTime(new SimpleDateFormat("yyyyMMdd").parse(d2));
			return (int) ((c2.getTimeInMillis() - c1.getTimeInMillis()) / (3600 * 24 * 1000))+"";
		} catch (ParseException e1) {
			e1.printStackTrace();
		}  
 
		return "";
	}	
	
	/**众筹剩余天数 输入:20161020  d2-now 输出天数**/
	public static int getProjectDays3(String d2) 
	{   
	
		SimpleDateFormat smdf = new SimpleDateFormat( "yyyyMMdd");
		String d1=smdf.format(new Date());
		
		Calendar c1 = Calendar.getInstance();
		Calendar c2 = Calendar.getInstance();
		try {
			
			
			c1.setTime(new SimpleDateFormat("yyyyMMdd").parse(d1));
			c2.setTime(new SimpleDateFormat("yyyyMMdd").parse(d2));
			return (int) ((c2.getTimeInMillis() - c1.getTimeInMillis()) / (3600 * 24 * 1000));
		} catch (ParseException e1) {
			e1.printStackTrace();
		}  
 
		return 0;
	}	
	
	
	/**开始时间 或 结束时间   输入：20161025152638               输出格式： XXXX年XX月XX日  **/
	public static String getDateYMD(String DateStr) 
	{
		DateStr=DateStr.substring(0, DateStr.length()-6);
		SimpleDateFormat sf1 = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat sf2 =new SimpleDateFormat("yyyy年MM月dd日");
		try {
		    DateStr = sf2.format(sf1.parse(DateStr));
		} catch (ParseException e) {

		   e.printStackTrace();
		}
		return DateStr;

	}	
	/**开始时间 或 结束时间   输入：20161025               输出格式： XXXX年XX月XX日  **/
	public static String getDateYMD2(String DateStr) 
	{
		SimpleDateFormat sf1 = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat sf2 =new SimpleDateFormat("yyyy年MM月dd日");
		try {
		    DateStr = sf2.format(sf1.parse(DateStr));
		} catch (ParseException e) {

		   e.printStackTrace();
		}
		return DateStr;

	}	
	
	
	public static String getDay() 
	{   
		return new SimpleDateFormat("yyyyMMdd").format(new Date());
	}
	
	public static String getHms_Str() 
	{   
		return new SimpleDateFormat("HHmmss").format(new Date());
	}
	
	public static long getYMDHms_long() 
	{   
		return getLongValue(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
	}
	public static long getYMDHms_long(Date d) 
	{   
		return getLongValue(new SimpleDateFormat("yyyyMMddHHmmss").format(d));
	}
	
	public static long getYMDHm_long() 
	{   
		return getLongValue(new SimpleDateFormat("yyyyMMddHHmm").format(new Date()));
	}
	public static long getYMDHm_long(Date d) 
	{   
		return getLongValue(new SimpleDateFormat("yyyyMMddHHmm").format(d));
	}	
	public static long getYMDHm_long(Date d,String format) 
	{   
		return getLongValue(new SimpleDateFormat(format).format(d));
	}	
	
	public static int getYMD_int() 
	{   
		return getIntValue(new SimpleDateFormat("yyyyMMdd").format(new Date()));
	}
	public static int getHm_int() 
	{   
		return getIntValue(new SimpleDateFormat("HHmm").format(new Date()));
	}
	public static int getHm_int(Date d) 
	{   
		return getIntValue(new SimpleDateFormat("HHmm").format(d));
	}
	public static int getHms_int() 
	{   
		return getIntValue(new SimpleDateFormat("HHmmss").format(new Date()));
	}
	
	public static int getHms_int(Date d,String format) 
	{   
		return getIntValue(new SimpleDateFormat(format).format(d));
	}
	/**输入 yyyyMMddHHmmss  得毫秒值**/
	public static long getMili(String DateStr) 
	{
		long t=0;
		SimpleDateFormat sf1 = new SimpleDateFormat("yyyyMMddHHmmss");
		try {
		    t=sf1.parse(DateStr).getTime();
		} catch (ParseException e) {

		   e.printStackTrace();
		}
		return t;

	}
	   /**date 转yyyymmdd等格式**/
    public static String date2String(Date time, String format) {
        try {
            SimpleDateFormat dateformat = new SimpleDateFormat(format);
            return dateformat.format(time);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    /**毫秒 转 yyyymmdd等格式**/
    public static String date2String(long time, String format) {
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(time);
            SimpleDateFormat dateformat = new SimpleDateFormat(format);
            return dateformat.format(calendar.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    /**yyyymmdd等格式转 date**/
    public static Date string2Date(String time, String format) {
        DateFormat dformat = null;
        try {
            dformat = new SimpleDateFormat(format);
            return dformat.parse(time);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }	
    /**
     * 日期逻辑
     *
     * @param timeMillis long型
     * @return
     */
    public static String timeLogic(long timeMillis, String format) {
        Calendar calendar = Calendar.getInstance();
        long now = calendar.getTimeInMillis();
        calendar.setTimeInMillis(timeMillis);
        long past = calendar.getTimeInMillis();

        // 相差的秒数
        long time = (now - past) / 1000;

        StringBuffer sb = new StringBuffer();
        if (time >= 0 && time < 60) { // 1小时内
            return sb.append(time + "秒前").toString();
        } else if (time > 60 && time < 3600) {
            return sb.append(time / 60 + "分钟前").toString();
        } else if (time >= 3600 && time < 3600 * 24) {
            return sb.append(time / 3600 + "小时前").toString();
        } else if (time >= 3600 * 24 && time < 3600 * 48) {
            return sb.append("昨天").toString();
        } else if (time >= 3600 * 48 && time < 3600 * 72) {
            return sb.append("前天").toString();
        } else if (time >= 3600 * 72) {
            return date2String(timeMillis, format);
        }
        return date2String(timeMillis, format);
    }
    
	/**
     * 获取几天前的时间
     * @param d
     * @param day
     * @return
     */
    public static Date getDateBeforeDay(Date date, int day) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
        
        return now.getTime();
    }
    
	/**
     * 获取几天前的时间  得字符串
     * @param d
     * @param day
     * @return
     */
    public static String getDateBeforeDay2(Date date,int day) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
        
        return new SimpleDateFormat("yyyyMMddHHmmss").format(now.getTime()); 
    }
    
	/**
     * 获取几天前的时间  得字符串
     * @param d
     * @param day
     * @return
     */
    public static String getDateBeforeDay3(Date date,int day) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
        
        return new SimpleDateFormat("yyyyMMddHHmm").format(now.getTime()); 
    }
    
    
	/**
     * 获取几天前的时间  得字符串
     * @param d
     * @param day
     * @return
     */
    public static String getDateBeforeDay4(Date date,int day) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
        
        return new SimpleDateFormat("yyyy-MM-dd").format(now.getTime()); 
    }
    
    
	/**
     * 获取几天前的时间
     * @param d
     * @param day
     * @return 20161025
     */
    public static int getDateBeforeDay2_Int(Date date, int day) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
        return getIntValue(getDateFormat("yyyyMMdd").format(now.getTime()));
    }
	
	/**
     * 获取几天后的时间
     * @param d
     * @param day
     * @return
     */
    public static Date getDateAfterDay(Date date, int day) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
        
        return now.getTime();
    }
    
    
	/**
     * 获取几天后的时间
     * @param d
     * @param day
     * @return 20161025
     */
    public static int getDateAfterDay2(Date date, int day) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
        return getIntValue(getDateFormat("yyyyMMdd").format(now.getTime()));
    }
    
    /**
     * 返回特定格式的日期
     * 格式如下:
     * yyyy-MM-dd
     * @param format
     * @return
     */
    public static String getFormatDate(Date date, String format){
        return getDateFormat(format).format(date);
    }
    
    /**
     * 返回特定格式的日期
     * 格式如下:
     * yyyy-MM-dd
     * @param format
     * @return
     */
    public static String getFormatDate(long miletime, String format){
        return getDateFormat(format).format(new Date(miletime));
    }
    
    /**
     * 将长时间格式字符串转换为时间
     * 如: yyyy-MM-dd HH:mm:ss
     */
	public static Date strToDate(String strDate, String format) {
		try {
			return getDateFormat(format).parse(strDate);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	public static SimpleDateFormat getDateFormat(String format){
		SimpleDateFormat formatter = new SimpleDateFormat(format);
		return formatter;
	}

	
	
	//两日期相差天数
	public static int GetDateSubDay(String d1,String d2)
	{
		if(CacheClass.isEmpty(d2)) return -1;
		int d1d2=-1;
		SimpleDateFormat smdf = new SimpleDateFormat( "yyyy-MM-dd"); 
		try { 
			Date start = smdf.parse( d1); 
			Date end = smdf.parse( d2); 
			d1d2 = (int) ((end.getTime() - start.getTime()) / (3600 * 24 * 1000)); 
 
		} catch (ParseException e) { 
			e.printStackTrace(); 
		}
		
		return d1d2;
	}

	//两日期相差天数
	public static int GetDateSubDay(Date d1,Date d2)
	{
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(d1);
		cal1.set(Calendar.HOUR_OF_DAY, 0);
		cal1.set(Calendar.MINUTE, 0);
		cal1.set(Calendar.SECOND, 0);  
		cal1.set(Calendar.MILLISECOND, 0);

		Calendar cal2 = Calendar.getInstance();
		cal2.setTime(d2);
		cal2.set(Calendar.HOUR_OF_DAY, 0);
		cal2.set(Calendar.MINUTE, 0);
		cal2.set(Calendar.SECOND, 0);  
		cal2.set(Calendar.MILLISECOND, 0);

		return (int) ((cal1.getTimeInMillis() - cal2.getTimeInMillis()) / (3600 * 24 * 1000)); 

	}
	
	//两日期相差天数 毫秒值
	public static int GetDateSubDay2(String d1,String d2)
	{
		if(CacheClass.isEmpty(d2)) return -1;
		int d1d2=-1;
		SimpleDateFormat smdf = new SimpleDateFormat( "yyyy-MM-dd");
		
		d1=smdf.format(new Date(getLongValue(d1)));
		d2=smdf.format(new Date(getLongValue(d2)));
		try { 
			Date start = smdf.parse( d1); 
			Date end = smdf.parse( d2); 
			d1d2 = (int) ((end.getTime() - start.getTime()) / (3600 * 24 * 1000)); 
 
		} catch (ParseException e) { 
			e.printStackTrace(); 
		}
		
		return d1d2;
	}

    //当月的第一天
	public static long getCurMonthFirstDay1()
	{
		 Date nowdate = new Date();
		 Calendar cal = Calendar.getInstance();
		 cal.setTime(nowdate);
		 cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
		 return cal.getTime().getTime();
	}
	public static Date getCurMonthFirstDay2()
	{
		 Date nowdate = new Date();
		 Calendar cal = Calendar.getInstance();
		 cal.setTime(nowdate);
		 cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
		 return cal.getTime();
	}
	
    //当月的最后一天
	public static long getCurMonthEndDay()
	{
		 Date nowdate = new Date();
		 Calendar cal = Calendar.getInstance();
		 cal.setTime(nowdate);
		 cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
		 return cal.getTime().getTime();
	}	
	
	/****/
	public static Date mileToDate(long miletime)
	{
		return new Date(miletime);
	}
	
	public static Date mileToDateAddSec(long miletime,int sed)
	{
		return new Date(miletime+(sed*1000));
	}
	
	/**某个时间date 的前后多少分钟 返回date**/
	public static Date DateAddMinute(Date d,int minute)
	{
		Calendar stopTime = Calendar.getInstance();
		stopTime.setTime(d);
		stopTime.add(Calendar.MINUTE, minute);
		stopTime.set(Calendar.SECOND, 0);  
		stopTime.set(Calendar.MILLISECOND, 0);
		return stopTime.getTime();
	}	
	
	/**某个时间date 的前后多少分钟 返回yyyyMMddHHmm long **/
	public static long getHm_Long_DateAddMinute(Date d,int minute)
	{
		Calendar stopTime = Calendar.getInstance();
		stopTime.setTime(d);
		stopTime.add(Calendar.MINUTE, minute);
		stopTime.set(Calendar.SECOND, 0);  
		stopTime.set(Calendar.MILLISECOND, 0);
		return getLongValue(new SimpleDateFormat("yyyyMMddHHmm").format(stopTime.getTime()));
	}

	public static long getHm_Long_DateAddMinute(Date d,int minute,String format)
	{
		Calendar stopTime = Calendar.getInstance();
		stopTime.setTime(d);
		stopTime.add(Calendar.MINUTE, minute);
		stopTime.set(Calendar.SECOND, 0);  
		stopTime.set(Calendar.MILLISECOND, 0);
		return getLongValue(new SimpleDateFormat(format).format(stopTime.getTime()));
	}
	
	/**某个时间date 的前后多少分钟        返回去掉秒后的毫秒 long **/
	public static long getMile_Long_DateAddMinute(Date d,int minute)
	{
		Calendar c = Calendar.getInstance();
		c.setTime(d); 
		c.add(Calendar.MINUTE, minute);
		c.set(Calendar.SECOND, 0);  
		c.set(Calendar.MILLISECOND, 0);
		return c.getTime().getTime();
	}


	
	 // 进行加法运算
    public static String Badd(String d1, String d2){        
        BigDecimal b1 = new BigDecimal(d1);
        BigDecimal b2 = new BigDecimal(d2);
        return b1.add(b2).toString();
    }
    // 进行减法运算
    public static String Bsub(String d1, String d2){        
        BigDecimal b1 = new BigDecimal(d1);
        BigDecimal b2 = new BigDecimal(d2);
        return b1.subtract(b2).toString();
    }
    public static BigDecimal Bsub_D(String d1, String d2){        
        BigDecimal b1 = new BigDecimal(d1);
        BigDecimal b2 = new BigDecimal(d2);
        return b1.subtract(b2);
    }
    // 进行乘法运算
    public static String Bmul(String d1, String d2){        
        BigDecimal b1 = new BigDecimal(d1);
        BigDecimal b2 = new BigDecimal(d2);
        return b1.multiply(b2).toString();
    }
    
    public static BigDecimal Bmul_D(String d1, String d2){        
        BigDecimal b1 = new BigDecimal(d1);
        BigDecimal b2 = new BigDecimal(d2);
        return b1.multiply(b2);
    }
    // 进行除法运算
    public static String Bdiv(String d1,String d2,int len) {
    	if(getFloatValue(d2)==0) return "0";
        BigDecimal b1 = new BigDecimal(d1);
        BigDecimal b2 = new BigDecimal(d2);
        return b1.divide(b2,len,BigDecimal.ROUND_HALF_UP).toString();
    }
    public static String Bdiv(String d1,String d2,int len,String def) {
    	if(getFloatValue(d2)==0) return def;
        BigDecimal b1 = new BigDecimal(d1);
        BigDecimal b2 = new BigDecimal(d2);
        return b1.divide(b2,len,BigDecimal.ROUND_HALF_UP).toString();
    }
    // 进行除法运算
    public static BigDecimal Bdiv_D(String d1,String d2,int len) {
    	if(getFloatValue(d2)==0) return new BigDecimal("0");
        BigDecimal b1 = new BigDecimal(d1);
        BigDecimal b2 = new BigDecimal(d2);
        return b1.divide(b2,len,BigDecimal.ROUND_HALF_UP);
    }
    public static BigDecimal Bdiv_D(String d1,String d2,int len,String def) {
    	if(getFloatValue(d2)==0) return new BigDecimal(def);
        BigDecimal b1 = new BigDecimal(d1);
        BigDecimal b2 = new BigDecimal(d2);
        return b1.divide(b2,len,BigDecimal.ROUND_HALF_UP);
    }   
    // 进行四舍五入操作
    public static String Bround(String d,int len) {     
        BigDecimal b1 = new BigDecimal(d);
        BigDecimal b2 = new BigDecimal(1);
        // 任何一个数字除以1都是原数字
        // ROUND_HALF_UP是BigDecimal的一个常量，表示进行四舍五入的操作
        return b1.divide(b2,len,BigDecimal.ROUND_HALF_UP).toString();
    }
    
    
    public static BigDecimal toBigDecimal(String d1){
    	if(getFloatValue(d1)==0) return new BigDecimal("0");
    	return new BigDecimal(d1);
    }
	
    public static String toBigDecimalString(String d1){
    	if(getFloatValue(d1)==0) return "0";
    	return d1;
    }  
    
	//星期几
	public static int dayForWeek(Date d) throws Exception {
		Calendar c = Calendar.getInstance();
		c.setTime(d);
		int dayForWeek = 0;
		if(c.get(Calendar.DAY_OF_WEEK) == 1){
			dayForWeek = 7;
		}else{
			dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
		}
		return dayForWeek;
	}
	//几号
	public static int dayForMonth(Date d) throws Exception {
		Calendar c = Calendar.getInstance();
		c.setTime(d);
		return c.get(Calendar.DAY_OF_MONTH);
	}
    
	
	public static void main(String args[])
	{
		System.getProperties().list(System.out);
			
		
	}
	
}
